package bk;

import java.awt.*;
import java.applet.*;
import javax.swing.JOptionPane;
public class Lab1106 extends Applet{
	private static final long serialVersionUID = 1L;
	final static Color BLACK = Color.black;
	final static Color RED = Color.red;
	final static Color WHITE = Color.white;
	final static Color BLUE = Color.blue;
	final static Color GREEN = Color.green;
	final static Color YELLOW = Color.yellow;
	final static int CAR_TYPES = 6;
	
	Color [] carColors =  {BLACK, RED, WHITE, BLUE, GREEN, YELLOW};
	int [] frequencies = {0, 0, 0, 0, 0, 0};
	String [] colorStrings = {"black", "red", "white", "blue", "green",   
	                            "yellow"};        
	public void init()
	{
	  for (int index = 0; index < CAR_TYPES; index++)
	  {
	    frequencies[index] = Integer.parseInt(JOptionPane.showInputDialog("How many " + colorStrings[index] + " cars?"));
	  }
	  setSize(400, 400);
	  setBackground(Color.gray);
	}
	
	public void paint(Graphics g)
	{
		int i=0;
		float sum=0;
		float angle_temp =0;
		float [] angle= {0,0,0,0,0,0,0};
		for (i=0;i<CAR_TYPES;i++)
		{
			sum=sum+ frequencies[i];		  
		}
		for (i=1;i<CAR_TYPES+1;i++)
		{
			angle[i]=angle_temp + (frequencies[i-1]/(float)sum)*360;
			angle_temp=angle[i];
		}
		for ( i=0;i< CAR_TYPES; i++)
		{
			g.setColor(carColors[i]);
			g.fillArc( 50, 50, 200, 200,(int) angle[i],(int) (angle[i+1]-angle[i]));
		}
	 }
}
